package com.example.controller.aboutStudent;

import com.example.vo.request.OperateStudentForm;
import com.example.vo.request.SearchStudentConditions;
import com.example.vo.response.StudentDTO;
import com.example.permission.PermissionCheck;
import com.example.service.aboutStudent.StudentService;
import com.example.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/student")
public class StudentController {

    @Resource
    private StudentService studentService;

    @GetMapping("/listStudents/{currentPage}/{pageSize}")
    @PermissionCheck(permissionPath = "/studentDataManagement")
    public Result listStudents(@PathVariable Integer currentPage, @PathVariable Integer pageSize) {
        return studentService.listStudents(currentPage, pageSize);
    }

    @PostMapping("/listStudentsByConditions")
    @PermissionCheck(permissionPath = "/studentDataManagement")
    public Result listStudentsByConditions(@RequestBody SearchStudentConditions searchStudentConditions) {
        return studentService.listStudentsByConditions(searchStudentConditions);
    }

    @PostMapping("/saveStudent")
    @PermissionCheck(permissionPath = "/studentDataManagement/addStudent")
    public Result saveStudent(@RequestBody OperateStudentForm operateStudentForm) {
        return studentService.saveStudent(operateStudentForm);
    }

    @PostMapping("/updateStudent")
    @PermissionCheck(permissionPath = "/studentDataManagement/operateStudent")
    public Result updateStudent(@RequestBody OperateStudentForm operateStudentForm) {
        return studentService.updateStudent(operateStudentForm);
    }

    @PostMapping ("/deleteStudent")
    @PermissionCheck(permissionPath = "/studentDataManagement/operateStudent")
    public Result deleteStudent(@RequestBody StudentDTO studentDTO) {
        return studentService.deleteStudent(studentDTO);
    }
}
